//
//  Settings.swift
//  NaiCha
//
//  Created by akk on 2024/9/12.
//

import SwiftUI

struct Settings: View {
    
    @Environment(\.presentationMode) private var presentationMode
    @EnvironmentObject var store: SettingStore
    
    var body: some View {
        NavigationStack {
            Form {
                Section {
                    Picker(selection: $store.selection) {
                        ForEach(SelectionEnum.allCases, id: \.self) { model in
                            Text(model.text).tag(model.rawValue)
                        }
                    } label: {
                        Text("显示模式")
                    }.pickerStyle(.automatic)
                    
                    Stepper("卡片间距\(store.gap)") {
                        if store.gap < 30{
                            store.gap += 1
                        }
                    } onDecrement: {
                        if store.gap > 5{
                            store.gap -= 1
                        }
                    }
                } header: {
                    Text("主页设置")
                }
                
                Section {
                    Toggle("展示描述", isOn: $store.toogle)
                } header: {
                    Text("详情页设置")
                }
            }.navigationTitle("设置")
                .navigationBarTitleDisplayMode(.inline)
                .navigationBarBackButtonHidden(true)
                .toolbar(content: {
                    ToolbarItem(placement: .topBarLeading) {
                        Button {
                            presentationMode.wrappedValue.dismiss()
                        } label: {
                            Image(systemName: "x.circle.fill").foregroundColor(.gray)
                        }
                    }
                })
        }
        
    }
}
struct SelectModel: Identifiable{
    var id: UUID = UUID()
    var item: String
}


#Preview {
    Settings()
}
